package com.iuie.ns.frame.web.dataset.context;

import java.util.List;

import com.iuie.ns.frame.web.dataset.description.DataSetDescription;
import com.iuie.ns.frame.web.dataset.vo.ColsVO;
import com.iuie.ns.frame.web.dataset.vo.DataSet;
import com.iuie.ns.frame.web.dataset.vo.Page;
import com.iuie.ns.frame.web.dataset.vo.RowsVO;

public final class DataSetUtil {
	
	private static final DataSetContext context = new DataSetContext();
	
	private DataSetUtil(){
		throw new AssertionError();
	}
	/**
	 * 将List集合对象转为Page相关的Map对象
	 * @param page
	 * @param clazz
	 * @return
	 * @throws ClassNotFoundException
	 */
	public static <T> DataSet listToDataSet(Page page,List<T> list,Class<?> clazz) throws ClassNotFoundException {
		return listToDataSet(page,list, clazz, "");
	}
	/**
	 * 将List集合对象转为Page相关的Map对象
	 * @param page
	 * @param clazz
	 * @param name
	 * @return
	 * @throws ClassNotFoundException
	 */
	public static <T> DataSet listToDataSet(Page page,List<T> list,Class<?> clazz,String name) throws ClassNotFoundException {
		DataSetDescription description = context.getDescription(clazz);
		List<ColsVO> cols = description.toDataSetColList(name);
		
		List<RowsVO> rows = context.toDataSetRowList(page,list,description,cols,clazz);
		
		DataSet dataSet = new DataSet();
		dataSet.setCols(cols);
		dataSet.setDatas(rows);
		
		return dataSet;
	}
}
